import sqlite3
#连接数据库
conn=sqlite3.connect("book.db")
#创建游标对象
cursor=conn.cursor()
#执行建表操作
# sql='''create table if not exists sys_user(
#         id int(11) primary key,
#         name varchar(25),
#         age int(3)
#         )'''
# cursor.execute(sql)
# conn.commit()

#插入数据
# insert_sql="insert into sys_user(id,name,age) values(?,?,?)"
# cursor.execute(insert_sql,(1,"root1",10))
# cursor.execute(insert_sql,(2,"root2",10))
# cursor.execute(insert_sql,(3,"root3",10))
# cursor.execute(insert_sql,(4,"root4",10))
# conn.commit()

#查询数据
select_sql="select * from sys_user"
# cursor.execute(select_sql)
# for row in cursor:
#     print(row)

cursor.execute(select_sql)
#result=cursor.fetchone()#只查询一行
#result=cursor.fetchmany(3)
# result=cursor.fetchall()#查询所有
# print(result)

#修改数据
update_sql="update sys_user set name=? where id=?"
cursor.execute(update_sql,("admin",1))
conn.commit()

#删除数据
delete_sql="delete from sys_user where id=?"
cursor.execute(delete_sql,(4,))
conn.commit()

cursor.execute(select_sql)
for row in cursor:
    print(row)

